/*
 * @(#)SageReader.java $version 2012. 1. 31.
 *
 */

package com.mywep.myalimi.batch.sage;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.NonTransientResourceException;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mywep.myalimi.common.DbConditionHolder;
import com.mywep.myalimi.model.Keyword;
import com.mywep.myalimi.repository.keyword.KeywordRepository;

import com.nhncorp.lucy.spring.core.util.ExtendedMap;

/**
 * @author 한지웅
 */
@Component
public class SageReader implements ItemReader<List<Keyword>> {
	@Autowired
	private KeywordRepository keywordRepository;

	/**
	 * @return
	 * @throws Exception
	 * @throws UnexpectedInputException
	 * @throws ParseException
	 * @throws NonTransientResourceException
	 * @see org.springframework.batch.item.ItemReader#read()
	 */
	@Override
	public List<Keyword> read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
		ExtendedMap param = DbConditionHolder.getInstance();
		param.put("lastAggregateDateLessThanNow", "Y");
		param.put("userCountThanZero", "Y");
		List<Keyword> keywordList = keywordRepository.selectByExample(param);

		if (CollectionUtils.isEmpty(keywordList)) {
			return null;
		}
		return keywordList;
	}

}
